import java.text.SimpleDateFormat

class SystemLogService {

    boolean transactional = true

    def writeLog(String remark,String userName) {
        SystemLog systemLog = new SystemLog()
        Date date=new Date()
        systemLog.setTime(date)
        systemLog.setUserName(userName)
        systemLog.setRemark(remark)
        systemLog.save()
    }

    def writeLogBackUpTime(Date backTime,String userName) {
        SystemLog systemLog = new SystemLog()
        Date date=new Date()
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
        def backTimeStr = sdf.format(backTime)
        systemLog.setTime(date)
        systemLog.setUserName(userName)
        systemLog.setRemark("定时于 "+backTimeStr+" 备份数据库")
        systemLog.save()
    }

    def writeLogWithCreateUser(String userName,String otherUserName) {
        SystemLog systemLog = new SystemLog()
        Date date=new Date()
        systemLog.setTime(date)
        systemLog.setUserName(userName)
        systemLog.setRemark("管理员"+userName+"创建新用户 "+otherUserName)
        systemLog.save()
    }

    def writeLogWithDeleteUser(String userName,String deleteUserName) {
        SystemLog systemLog = new SystemLog()
        Date date=new Date()
        systemLog.setTime(date)
        systemLog.setUserName(userName)
        systemLog.setRemark("管理员"+userName+"删除用户 "+deleteUserName)
        systemLog.save()
    }
}
